package com.beehoo.dcportal.admin.action;

import java.util.List;

import com.beehoo.dcportal.admin.service.ComplaintService;
import com.beehoo.dcportal.common.Constant;
import com.beehoo.dcportal.common.base.BaseAction;
import com.beehoo.dcportal.common.base.BaseException;
import com.beehoo.dcportal.model.ComplaintBean;
import com.beehoo.dcportal.utils.CommonUtils;

public class ComplaintAction extends BaseAction {

	private static final long serialVersionUID = -496180817387933857L;
	private ComplaintService complaintService;
	private ComplaintBean complaintBean;
	private List<ComplaintBean> resultList;
	private String queState;
	private String beginDate;
	private String endDate;
	private String queId;
	private int totalRows;                   //列表条目总数
	private int pageRows;                    //每页条目数
	private int pageNo;                      //当前页码
	private String naction;                   //请求地址

	public int getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}

	public int getPageRows() {
		return pageRows;
	}

	public void setPageRows(int pageRows) {
		this.pageRows = pageRows;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public String getNaction() {
		return naction;
	}

	public void setNaction(String naction) {
		this.naction = naction;
	}

	public ComplaintBean getComplaintBean() {
		return complaintBean;
	}

	public void setComplaintBean(ComplaintBean complaintBean) {
		this.complaintBean = complaintBean;
	}

	public List<ComplaintBean> getResultList() {
		return resultList;
	}

	public void setResultList(List<ComplaintBean> resultList) {
		this.resultList = resultList;
	}

	public String getQueState() {
		return queState;
	}

	public void setQueState(String queState) {
		this.queState = queState;
	}

	public String getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(String beginDate) {
		this.beginDate = beginDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public String getQueId() {
		return queId;
	}

	public void setQueId(String queId) {
		this.queId = queId;
	}

	public void setComplaintService(ComplaintService complaintService) {
		this.complaintService = complaintService;
	}

	public String list() {
		initDate();
		String streetId = (String) getSession().get(Constant.SESSION_STREET_ID);
		if (CommonUtils.nvlToString(queState).equals(""))
			queState = "0";
		
		pageRows = Constant.ADMIN_DEFAULT_ROWS;
		if(pageNo == 0)
			pageNo = 1;
		
		try {
			resultList = complaintService.queryComplaints(streetId, queState,
					beginDate, endDate, pageNo, pageRows);
			totalRows = complaintService.queryComplaintCount(streetId,
					queState, beginDate, endDate);
			naction = "/admin/complaint!list.action";
		} catch (BaseException e) {
			setMessage(super.getText(e.getMessage()));
		}
		return SUCCESS;
	}
	
	public String initAudit() {
		String streetId = (String) getSession().get(Constant.SESSION_STREET_ID);
		try {
			complaintBean = complaintService.queryComplaint(streetId, queId);
		} catch (BaseException e) {
			setMessage(super.getText(e.getMessage()));
		}
		return "audit";
	}
	
	public String audit() {
		try {
			String auditorId = (String) getSession().get(Constant.SESSION_USER_ID);
			String auditor = (String) getSession().get(Constant.SESSION_USER_NAME);
			if(complaintBean != null){
				complaintBean.setAuditorId(auditorId);
				complaintBean.setAuditor(auditor);
			}
			complaintService.auditComplaint(complaintBean);
		} catch (BaseException e) {
			setMessage(super.getText(e.getMessage()));
		}
		return list();
	}
	
	public String del() {
		try {
			complaintService.delComplaint(queId);
		} catch (BaseException e) {
			setMessage(super.getText(e.getMessage()));
		}
		return list();
	}

	private void initDate() {
		if (CommonUtils.nvlToString(beginDate).equals(""))
			beginDate = CommonUtils.getPastDay(7);
		if (CommonUtils.nvlToString(endDate).equals(""))
			endDate = CommonUtils.getDate();
	}
}
